package com.demo.pattern.singleton;

/**
 * @author linchong
 * @version 1.0
 * @Date: 2022-05-22 12:52
 * @Description: LazyDoubleCheckSingleton$
 */
public class LazyDoubleCheckSingleton {

	private LazyDoubleCheckSingleton(){};

	private volatile static LazyDoubleCheckSingleton instance;

	public static LazyDoubleCheckSingleton getInstance(){

		//第一次检测
		if(instance == null){
			//同步
			synchronized (LazyDoubleCheckSingleton.class){
				if(instance == null){
					//memory = allocate(); //1.分配对象内存空间
					//instance(memory); //2，初始化对象
					//instance = memory; //3.设置instance指向刚分配的内存地址，此时instance != null
					instance = new LazyDoubleCheckSingleton();
				}
			}
		}
		return instance;
	}
}
